Machine Library

I've created a library targeting the hardware specific aspects of programming the Sbc-3. I believe that it should work with the other boards from Mega Micros, but since I don't have access to anything but the Sbc-3, can't confirm that.

Warning

if compiling for the 68000, you'll need to change the target cpu in src/stdenv.mk and src/lib/Makefile by changing the CPU macro.

To use the library, just include the following in your C sourcecode:

#include <machine.h>

Serial I/O

int _char_available(void);
char _getchar(void);
void _putchar(char c);
Note

The xr68681 is clocked at 7.3728MHz, meaning you'll get double the baud rate listed in the data sheet as the datasheet assumes half that rate. It will also affect the internal counter when it's clocked by the external clock.


LED Control

There's a block of 10 leds (LD7 on the SBC3-b3), and six of them can be used for anything you like. Led1 is furthest from the cpu:

LED # Used for
1 Indicates that the board is being powered via an external 5v supply.
2 Indicated that the board is being powered via the ATX power connector.
3 Connected to the ~RTS pin on the duart channel B.
4 Connected to the ~RTS pin on the duart channel A.
5 Available to user.
6 Available to user.
7 Available to user.
8 Available to user.
9 Available to user.
10 Available to user.

Two functions are provided, one to turn on a led, and another to turn it off.

void set_led(int lednum);
void clear_led(int lednum);

Where lednum is an integer in the range of 5 through to 10, as per the table above. Any other value will be silently ignored.

PI/T

The runtime startup (crt0) contains code which sets up an interrupt handler for the PIT timer and configures the counter to interrupt every millisecond.

void _pit_reset(void);
unsigned int pit_get_counter(void);
unsigned int pit_set_counter(unsigned int);
uint32_t ticks(void);
void idle_for_ticks(uint32);

void pit_set_a(uint8_t val);
void pit_set_bits_a(uint8_t bits);
void pit_clear_bits_a(uint8_t bits);
void pit_set_b(uint8_t val);
void pit_set_bits_b(uint8_t bits);
void pit_clear_bits_b(uint8_t bits);
Note

The PI/T is clocked at 10.0MHz

Compact Flash

void _cf_wait_busy(void);
void _cf_wait_data(void);
void cf_init(void);
int cf_identify(uint8_t drive_num, cf_info_t *info);
int cf_read(uint8_t drive_num, uint32_t sector, uint8_t *buffer);

Vectors and Interrupts

unsigned int *_get_vectors_base(void);
unsigned int get_isr_handler(int vector_number);
unsigned int set_isr_handler(int vector_number, void isr(void));

_get_vectors_base() return the contents of the ivr register on the 68030 or 0 on the 68000.

get_isr_handler returns the address of the handler currently configured to handle the exception specified by vector_number.

set_isr_handler() sets a handler for the exception specified by vector_number. It returns the address of the handler that it replaced, or 0xffffffff if the vector_number is out of range.

\(I^2c\) Bus

Safe Memory Access

int peek(uint8_t *addr);
int poke(uint8_t *addr, uint8_t val);

peek() attempts to read a byte from memory, returning the value read, or -1 if the read failed due to a Bus Error. Similarly, poke() attempts to write a byte to memory, returning -1 on a Bus Error.

0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9